package com.sun.androidexerciseproject.function.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Steven on 2016/7/19 0019.
 */

public class WeatherHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME = "test";
    private static final String DATABASE_NAME = "wheather.db";
    private static final int DATABASE_VERSION = 1;

    public WeatherHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        createTable(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = "drop table if exists " + TABLE_NAME;
        db.execSQL(sql);
        createTable(db);

    }

    private void createTable(SQLiteDatabase db) {
        String sql = "create table if not exists" + TABLE_NAME + "(Id integer primary key, Name text not null, City text not null)";
        db.execSQL(sql);
    }
}
